package ahaArithmetic;

public class Dfs {
    static int n = 9;
    static int[] numbers = new int[n];
    static int[] a = new int[n];
    static int result = 0;

    // [][][]+[][][] = [][][] 填入九个数，让等式成立
    public static void main(String[] args) {
        dfs_1(0);
        System.out.print(result/2);
    }

    public static void dfs_1(int k){
        if(k==n){
            if(a[0]*100+a[1]*10+a[2]+a[3]*100+a[4]*10+a[5] == a[6]*100+a[7]*10+a[8]){
                dfs_1_print();
            }
            return;
        }
        for(int i =0;i<n;i++){
            if(numbers[i]==1){
                continue;
            }
            a[k] = i+1;
            numbers[i] = 1;
            dfs_1(k+1);
            numbers[i] = 0;
        }
    }
    public static void dfs_1_print(){
        System.out.println(a[0]+""+a[1]+""+a[2]+"+"+a[3]+""+a[4]+""+a[5]+"="+a[6]+""+a[7]+""+a[8]);
        result++;
    }
}
